package com.etc

import org.apache.spark.{SparkConf, SparkContext}

/**
  * @Auther: Wangcc
  * @Date: 2018/8/17 18:21
  * @Description: 每行出现次数 scala版本
  */
object LineCountScala {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      .setAppName("LineCount")
      .setMaster("local")
    val sc = new SparkContext(conf);

    val lines = sc.textFile("C://Users//Administrator//Desktop//hello.txt", 1)
    val pairs = lines.map { line => (line, 1) }
    val lineCounts = pairs.reduceByKey { _ + _}

    lineCounts.foreach(lineCount => println(lineCount._1 + " appears " + lineCount._2 + " times."))
  }
}
